<template>
  <div class="Project">
    <Management>
      <Top
        slot="top"
        @showModel="showModel"
        @showAll="showAll"
        :add="false"
        :excel="false"
        :search="false"
      ></Top>
      <Table
        slot="body"
        :title="columns"
        :tableData="data"
        :current="current"
        @edit="edit"
        :show-del="true"
        edit-txt="审核"
        del-txt="删除"
        @del="del"
        @changePage="changePage"
        :total="total"
      ></Table>
    </Management>
    <Card
      :list="this.row"
      :show="isShow"
      @confirm="confirm"
      @cancel="closeDialog"
      @nopass="cancel"
    >
      <div name="card">ss</div>
    </Card>
  </div>
</template>

<script>
import Table from "@/components/common/table/Table";
import Management from "components/common/management/Management";
import Top from "./component/Top";
import Dialog from "./component/Dialog";
import Card from "./component/Card";

import { getDataByPageAndSize, Check,deleteById } from "@/network/Base/signup";
export default {
  props: {
    list: {
      type: Boolean,
      default() {
        return false;
      },
    },
    id: {
      type: Number,
      default() {
        return NaN;
      },
    },
  },
  components: { Card, Table, Top, Dialog, Management },
  name: "Signup",
  data() {
    const columns = [
      {
        title: "id",
        dataIndex: "id",
      },
      {
        title: "学生id",
        dataIndex: "studentId",
      },
      {
        title: "学生姓名",
        dataIndex: "name",
      },
      {
        title: "是否对口",
        dataIndex: "suitable",
      },
      {
        title: "是否被录取",
        dataIndex: "success",
      },
      {
        title: "企业名称",
        dataIndex: "company",
      },
      {
        title: "报名职务",
        dataIndex: "job",
      },
    ];
    return { columns, isShow: false, data: [], total: 0, row: {}, current: 1 };
  },
  created() {
    console.log("111222333444");
    this.init();
  },
  methods: {
    /**
     * @description: 初始化页面
     * @param {Number} page
     * @param {Number} size
     * @author: tao
     */
    async init(page = 1, size = 10) {
      console.log(1122);
      if (!this.list) {
        const result = await getDataByPageAndSize(page, size);
        console.log(result);
        if (result.msg) {
          this.data = result.data;
          this.total = result.count;
          this.current = page;
        }
      } else {
        const result = await getDataByPageAndSize(page, size);
        console.log(result);
        if (result.msg) {
          this.data = result.data;
          this.total = result.count;
        }
      }
    },
    async confirm(e) {
      console.log(e);
      this.closeDialog();
      this.$notification["success"]({
        message: "已经更新啦！",
        description: "已更新所有消息",
      });
      //生成数据
      const res = await Check(e.id, e.check);
      console.log(res);
      if (res.msg) {
        await this.init();
      }
    },

    changePage(page) {
      this.init(page);
    },

    async onSearch(value) {
      const result = await searchById(value);
      this.tableData = result.data.map((item) => {
        item.type = paperType[+item.type];
        item.check = check[+item.check];
        return item;
      });
    },

    async checked(e) {
      console.log(e);
      this.closeDialog();
    },
    showAll() {
      this.$notification["success"]({
        message: "显示成功！",
        description: "已显示所有消息",
      });
      this.init();
    },
    showModel() {
      this.isShow = true;
      this.row = { time: null };
    },
    async del(e) {
      console.log(e.id);
      const result = await deleteById(e.id);
      console.log(result);
      if (result.msg) {
        this.init();
      }
    },
    async edit(e) {
      this.isShow = true;
      this.row = { ...e, edit: true };
      let member = this.row.member;
    },
    handleCheck(e) {
      this.checking = true;
      this.row = { ...e, checking: true };
    },
    async cancel(e) {
      console.log("sign");
      this.closeDialog();
      this.$notification["success"]({
        message: "已经更新啦！",
        description: "已更新所有消息",
      });
      //生成数据
      const res = await Check(e.id, e.check);
      console.log(res);
      if (res.msg) {
        await this.init();
      }
    },
    closeDialog() {
      this.isShow = false;
      this.row = { time: null };
    },
  },
};
</script>

<style scoped>
</style>